package com.dream.model.stock;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Type;

import com.dream.model.base.AppUserModelBase;
import com.dream.model.master.ProductPart;
import com.dream.model.master.Shop;
import com.dream.model.stock.ProductPartStock.StockProductType;
import com.google.common.collect.Maps;

@Entity
@Table(name="t_mst_product_part_request")
public class ProductPartRequest extends AppUserModelBase implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = -7740064725328076630L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id ;
	
	@Column(name="manual_id")
	private String manualId;

	@Column(name="pro_part_id")
	private String productPartId;
	
	@Column(name="request_num")
	private Integer requestNum;
	
	@Column(name="request_type")
	@Enumerated(EnumType.STRING)
	private StockDirection requestType;
	
	@Column(name="stock_type")
	@Enumerated(EnumType.STRING)
	private StockProductType stockType = StockProductType.new_product;
	
	@Column(name="request_item_comment")
	private String requestItemComment;
	
	@Column(name="deleted")
	@Type(type = "org.hibernate.type.NumericBooleanType")
	private Boolean deleted = false;
	
	@Column(name="request_user")
	private String requestUser;
	
	@Column(name="request_date")
	@Temporal(TemporalType.TIMESTAMP)
	private Date requestDate ;
	
	@Column(name="from_shop_id")
	private String fromShopId;
	
	@Column(name="to_shop_id")
	private String toShopId;
	
	@Column(name="request_commont")
	private String requestCommont;
	
	@Column(name="status")
	@Enumerated(EnumType.STRING)
	private RequestStatus status;
	
	
	@Column(name="approve_comment")
	private String approveCommont;
	
	@Column(name="unnormal_num")
	private Integer unnormalNum = 0;
	
	@Column(name="unnormal_type")
	private Long unnormalType;
	
	@Column(name="rcv_comment")
	private String rcvComment;
	
	@Column(name="express_id")
	private Long expressId;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="pro_part_id",updatable=false,insertable=false)
	private ProductPart productPart;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="from_shop_id",updatable=false,insertable=false)
	private Shop fromShop;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="to_shop_id",updatable=false,insertable=false)
	private Shop toShop;
	
	public Long getExpressId() {
		return expressId;
	}

	public void setExpressId(Long expressId) {
		this.expressId = expressId;
	}

	public String getApproveCommont() {
		return approveCommont;
	}

	public void setApproveCommont(String approveCommont) {
		this.approveCommont = approveCommont;
	}

	public Integer getUnnormalNum() {
		return unnormalNum;
	}

	public void setUnnormalNum(Integer unnormalNum) {
		this.unnormalNum = unnormalNum;
	}

	public Long getUnnormalType() {
		return unnormalType;
	}

	public void setUnnormalType(Long unnormalType) {
		this.unnormalType = unnormalType;
	}

	public String getRcvComment() {
		return rcvComment;
	}

	public void setRcvComment(String rcvComment) {
		this.rcvComment = rcvComment;
	}

	public Shop getFromShop() {
		return fromShop;
	}

	public void setFromShop(Shop fromShop) {
		this.fromShop = fromShop;
	}

	public Shop getToShop() {
		return toShop;
	}

	public void setToShop(Shop toShop) {
		this.toShop = toShop;
	}

	public RequestStatus getStatus() {
		return status;
	}

	public void setStatus(RequestStatus status) {
		this.status = status;
	}


	public String getManualId() {
		return manualId;
	}

	public void setManualId(String manualId) {
		this.manualId = manualId;
	}

	public StockProductType getStockType() {
		return stockType;
	}

	public void setStockType(StockProductType stockType) {
		this.stockType = stockType;
	}
	
	public ProductPart getProductPart() {
		return productPart;
	}

	public void setProductPart(ProductPart productPart) {
		this.productPart = productPart;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getProductPartId() {
		return productPartId;
	}

	public void setProductPartId(String productPartId) {
		this.productPartId = productPartId;
	}

	
	public Integer getRequestNum() {
		return requestNum;
	}

	public void setRequestNum(Integer requestNum) {
		this.requestNum = requestNum;
	}

	public StockDirection getRequestType() {
		return requestType;
	}

	public void setRequestType(StockDirection requestType) {
		this.requestType = requestType;
	}

	public String getRequestItemComment() {
		return requestItemComment;
	}

	public void setRequestItemComment(String requestItemComment) {
		this.requestItemComment = requestItemComment;
	}

	public String getRequestUser() {
		return requestUser;
	}

	public void setRequestUser(String requestUser) {
		this.requestUser = requestUser;
	}

	public Date getRequestDate() {
		return requestDate;
	}

	public void setRequestDate(Date requestDate) {
		this.requestDate = requestDate;
	}

	public String getFromShopId() {
		return fromShopId;
	}

	public void setFromShopId(String fromShopId) {
		this.fromShopId = fromShopId;
	}

	public String getToShopId() {
		return toShopId;
	}

	public void setToShopId(String toShopId) {
		this.toShopId = toShopId;
	}

	public String getRequestCommont() {
		return requestCommont;
	}

	public void setRequestCommont(String requestCommont) {
		this.requestCommont = requestCommont;
	}

	public Boolean getDeleted() {
		return deleted;
	}

	public void setDeleted(Boolean deleted) {
		this.deleted = deleted;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ProductPartRequest other = (ProductPartRequest) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	public static enum StockDirection{in,out;
	  private static final Map<String,StockDirection> map = Maps.newConcurrentMap();
	  static{
		  for(StockDirection item :values()){
			  map.put(item.name(), item);
		  }
	  }
	 
	  public static StockDirection getInstance(String name){
		  if(StringUtils.isBlank(name)) return null;
		  return map.get(name);
	  }
	}
	public static enum RequestStatus{submit,approve,reject,post,received,other;
		  private static final Map<String,RequestStatus> map = Maps.newConcurrentMap();
		  static{
			  for(RequestStatus item :values()){
				  map.put(item.name(), item);
			  }
		  }
		 
		  public static RequestStatus getInstance(String name){
			  if(StringUtils.isBlank(name)) return null;
			  return map.get(name);
		  }
	  }
}
